import { _decorator, Component, Node, Label, director } from 'cc';
import { SSS_Consts } from "../../../Script/Data/SSS_Consts";
import { S2048_GameData } from "./S2048_GameData";
import S2048_GameManager from "./S2048_GameManager";
import { S2048_GameStorage } from "./S2048_GameStorage";
import { SSS_AudioManager } from 'db://assets/Script/Manager/SSS_AudioManager';

const { ccclass, property } = _decorator;

@ccclass('S2048GamePanel')
export default class S2048_GamePanel extends Component {
    static Instance: S2048_GamePanel;
    @property(Node)
    Button_back: Node | null = null;
    @property(Node)
    Button_refresh: Node | null = null;
    @property(Label)
    Label_score: Label | null = null;
    @property(Label)
    Label_highScore: Label | null = null;
    
    GeneratePoint_blook_list = [];
    GeneratePoint_blook_list_temp = [];
    onLoad() {
        S2048_GamePanel.Instance = this;
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();
    }
    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }
    Refresh() {
        this.Refresh_score();
    }
    Refresh_score() {
        //     this.Label_score.string = `本局得分：${S2048_GameData.GetScore()}`;
        //     this.Label_highScore.string = `最高纪录：${S2048_GameStorage.data.high_score}`;
        this.Label_score.string = `${S2048_GameData.GetScore()}`;
        this.Label_highScore.string = `${S2048_GameStorage.data[S2048_GameData.Game_mode].high_score}`;
    }
    AddListener() {
        this.Button_back.on(Node.EventType.TOUCH_END, this.On_Button_back, this);
        this.Button_refresh.on(Node.EventType.TOUCH_END, this.On_Button_refresh, this);

    }
    RemoveListener() {
        this.Button_back.off(Node.EventType.TOUCH_END, this.On_Button_back, this);
        this.Button_refresh.off(Node.EventType.TOUCH_END, this.On_Button_refresh, this);
    }
    On_Button_back() {
        director.loadScene(SSS_Consts.SceneName.S2048_Main_Scene);
        // director.loadScene("MainScene");

        SSS_AudioManager.PlayButtonAudio();
    }
    On_Button_refresh() {
        S2048_GameManager.Instance.Replay();

        SSS_AudioManager.PlayButtonAudio();
    }
}

// /** 调试 */
window["S2048_GamePanel"] = S2048_GamePanel;